﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
@*
    登录/注册页面参考示例：
    https://bootsnipp.com/tags/registration
    https://bootsnipp.com/snippets/featured/google-style-login

    form表单验证：采用jquery验证插件（不要找其他的了）
*@
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>@ViewData["Title"]</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" href="@Url.Content("~/lib/AdminLTE/bower_components/bootstrap/dist/css/bootstrap.min.css")">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="@Url.Content("~/lib/AdminLTE/bower_components/font-awesome/css/font-awesome.min.css")">
    <!-- Ionicons -->
    <link rel="stylesheet" href="@Url.Content("~/lib/AdminLTE/bower_components/Ionicons/css/ionicons.min.css")">
    <!-- Theme style -->
    <link rel="stylesheet" href="@Url.Content("~/lib/AdminLTE/dist/css/AdminLTE.min.css")">
    <!-- iCheck -->
    <link rel="stylesheet" href="@Url.Content("~/lib/AdminLTE/plugins/iCheck/square/blue.css")">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <!-- Google Font -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>
<body class="hold-transition login-page">
    <div class="login-box">
        <div class="login-logo">
            @*<a href="../../index2.html"><b>Admin</b>LTE</a>*@
            <b>D</b>I
        </div>
        <!-- /.login-logo -->
        <div class="login-box-body">
            <form id="loginForm">
                <p class="login-box-msg">欢 迎</p>
                <div class="form-group has-feedback">
                    @*<input type="email" class="form-control" placeholder="Account" id="UserName">*@
                    @*@Html.TextBoxFor(m => m.UserName, new { @class = "form-control", @placeholder = "Account" })*@
                    <input type="text" class="form-control" placeholder="账户/邮箱/手机号码" id="UserName" name="UserName" maxlength="30">
                    <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
                </div>
                <div class="form-group has-feedback">
                    @*@Html.PasswordFor(m => m.Password, new { @class = "form-control", @placeholder = "Password" })*@
                    <input type="password" class="form-control" placeholder="请输入密码" id="Password" name="Password" maxlength="20">
                    <span class="glyphicon glyphicon-lock form-control-feedback"></span>
                </div>
                <div class="row">
                    <div class="col-xs-8">
                        <div class="checkbox icheck">
                            <label>
                                <input type="checkbox" id="rememberme"> 记住我
                            </label>
                        </div>
                    </div>
                    <!-- /.col -->
                    <div class="col-xs-4">
                        @*<button type="submit" class="btn btn-primary btn-block btn-flat">登&nbsp;&nbsp;录</button>*@
                        <input type="button" class="btn btn-primary btn-block btn-flat" id="btnLogin" value="登  录" />
                    </div>
                    <!-- /.col -->
                </div>
                @*<div class="social-auth-links text-center">
                        <p>- OR -</p>
                        <a href="#" class="btn btn-block btn-social btn-facebook btn-flat">
                            <i class="fa fa-facebook"></i> Sign in using
                            Facebook
                        </a>
                        <a href="#" class="btn btn-block btn-social btn-google btn-flat">
                            <i class="fa fa-google-plus"></i> Sign in using
                            Google+
                        </a>
                    </div>*@
                <!-- /.social-auth-links -->
                @*<a href="#">I forgot my password</a><br>
                    <a href="register.html" class="text-center">Register a new membership</a>*@
                <span style="color:red;" class="login-box-msg right" id="errorMsg"></span>
            </form>
        </div>
        <!-- /.login-box-body -->
    </div>
    <!-- /.login-box -->
    <!-- jQuery 3 -->
    <script src="@Url.Content("~/lib/AdminLTE/bower_components/jquery/dist/jquery.min.js")"></script>
    <!-- Bootstrap 3.3.7 -->
    <script src="@Url.Content("~/lib/AdminLTE/bower_components/bootstrap/dist/js/bootstrap.min.js")"></script>
    <!-- iCheck -->
    <script src="@Url.Content("~/lib/AdminLTE/plugins/iCheck/icheck.min.js")"></script>
    <script src="@Url.Content("~/lib/jquery-validation/dist/jquery.validate.min.js")"></script>
    <script src="@Url.Content("~/lib/jquery-validation/dist/localization/messages_zh.min.js")"></script>
    <script src="@Url.Content("~/lib/layer/layer.js")"></script>
    <script src="@Url.Content("~/lib/url.js")"></script>
    <script src="@Url.Content("~/lib/AlertMessage.js")"></script>
    <script>
        $(function () {
            @*var errorMsg = "@ViewBag.ErrorMessage";
            //弹出操作失败信息
            if (errorMsg.length > 0) {
                layer.alert(errorMsg, {
                    icon: 2
                    , title: '操作出错'
                    , closeBtn: 1, //显示关闭按钮
                    anim: 2,
                    shadeClose: true, //开启遮罩关闭

                });
            }*@
            @*
            /*
             * 作为开发参考注释，不能在网页中显示
             * 表单校验
             * 参考：jquery-validation/demo/bootstrap/index.html 设计
             *
             */
            *@
            $("#loginForm").validate({
                rules: {
                    UserName: {
                        required: true,
                        minlength: 3,
                        maxlength: 30
                    },
                    Password: {
                        required: true,
                        minlength: 6,
                        maxlength: 20
                    }
                },
                messages: {
                    username: {
                        required: "请输入用户名",
                        minlength: "用户名最少需要输入3个字符",
                        maxlength: "用户名最多只能输入30个字符"
                    },
                    password: {
                        required: "请输入密码",
                        minlength: "用户名最少需要输入6个字符",
                        maxlength: "用户名最多只能输入20个字符"
                    }
                },
                errorElement: "em",
                errorPlacement: function (error, element) {
                    // Add the `help-block` class to the error element
                    error.addClass("help-block");

                    if (element.prop("type") === "checkbox") {
                        error.insertAfter(element.parent("label"));
                    } else {
                        error.insertAfter(element);
                    }
                },
                highlight: function (element, errorClass, validClass) {
                    $(element).parents(".col-sm-5").addClass("has-error").removeClass("has-success");
                },
                unhighlight: function (element, errorClass, validClass) {
                    $(element).parents(".col-sm-5").addClass("has-success").removeClass("has-error");
                }
            });

            $('input').iCheck({
              checkboxClass: 'icheckbox_square-blue',
              radioClass: 'iradio_square-blue',
              increaseArea: '20%' // optional
            });

            /* 登录事件 */
            $("#btnLogin").click(function () {
                var validateResult = $("#loginForm").validate();
                if (validateResult.errorList.length > 0) return;

                var userName = $("#UserName").val();
                if (!userName) {
                    $("#errorMsg").text("请输入用户名");
                    return false;
                }
                var password = $("#Password").val();
                if (!password) {
                    $("#errorMsg").text("请输入密码");
                    return false;
                }
                var isremember = $("#rememberme").is(":checked");
                $.ajax({
                    type: "POST",
                    url: loginUrl,
                    data: { userName: userName, password: password, remember: isremember },
                    dataType: receiveDataType,
                    success: function (data) {
                        var jsonData = eval(data);
                        //判断是否登录成功
                        if (jsonData.isSuccess) {
                            window.location.href = mainWebUrl;
                        }
                        else {
                            //AlertTips("#UserName", jsonData.description);
                            //AlertTips("#Password", jsonData.description);
                            $("#errorMsg").text(jsonData.description);
                        }

                    }
                });

            });

          });
    </script>
</body>
</html>

